package com.github.abel533.postprocessor.environment;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;

import static com.github.abel533.C.print;

/**
 * @author liuzh
 */
@Configuration
public class EnvironmentPostProcessorImpl implements EnvironmentPostProcessor, BeanPostProcessor, BeanFactoryPostProcessor {

    @Override
    public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
        print("EnvironmentPostProcessor#postProcessEnvironment");
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        print("BeanFactoryPostProcessor#postProcessBeanFactory");
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        print("BeanPostProcessor#postProcessBeforeInitialization - " + beanName);
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        print("BeanPostProcessor#postProcessAfterInitialization - " + beanName);
        return bean;
    }
}
